$(function(){

});

//设置性别
function setSex(obj) {
	var param = {
		id:$(obj).attr("dataId"),
		sex:$(obj).val()
	};
	API.diseaseSetSex(param, function(res) {
		if(res.code == 0) {
			
		} else {
			alert(res.desc);
		}
	});
}

//设置年龄
function setAge(obj) {
	var param = {
		"id":$(obj).attr("dataId"),
		"age":$(obj).val(),
		"flag":$(obj).prop("checked") + ""
	};
	API.diseaseSetAge(param, function(res) {
		if(res.code == 0) {
			
		} else {
			alert(res.desc);
		}
	});
}

function sexClick(obj) {
	var v1 = $("#keyword").val();
	var v3 = $("#tabid").val();
	var v4 = $("#sexKey").val();
	var hrefStr = "/icd/disease_sex_age_list.htm?tabid=" + v3 + "&keyword=" + v1 + "&sexKey=";
	if(v4 != $(obj).attr("title")) {
		hrefStr += $(obj).attr("title");
	}
	location.href = hrefStr;
}

function submitSexAge(obj) {
	if(UTIL.checkButton(obj)) {
		var ids = '';

		$("select[name='sex']").each(function() {
			ids += $(this).attr("dataId") + ",";
		});
		var param = {
			"ids" : ids
		};
		API.diseaseSubmitSexAge(param, function(res) {
			if(res.code == 0) {
				window.location.reload();
				$(window).scrollTop(0);
			} else {
				alert(res.desc);
			}
			UTIL.releaseButton(obj);
		});
	}
}

function exportSexAge(obj) {
	if(UTIL.checkButton(obj)) {
		window.location.href="/icd/disease_export_sex_age.htm";
		UTIL.releaseButton(obj);
	}
}

function selectAll(obj, classname) {
	if($(obj).prop("checked")) {
		$("." + classname).prop("checked", true);
	} else {
		$("." + classname).prop("checked", false);
	}
	$("." + classname).each(function() {
		setAge(this);
	});
}

function sexAllChange(sexNum) {
	$(".sexSelect").val(sexNum);
	$(".sexSelect").each(function() {
		setSex(this);
	});
}
